﻿<UserControl x:Class="TreeBuilder.Tree"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:tb="clr-namespace:TreeBuilder" 
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300"
             >
    <UserControl.Resources>
        <DrawingBrush x:Key="DottedBrush" Stretch="Fill" TileMode="Tile"
                      Viewbox="0,0,10,10" ViewboxUnits="Absolute"
                      Viewport="0,0,10,10" ViewportUnits="Absolute">
            <DrawingBrush.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="White">
                        <GeometryDrawing.Pen>
                            <Pen Brush="White" Thickness="2"/>
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="0,0,10,10"/>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                    <GeometryDrawing Brush="White">
                        <GeometryDrawing.Pen>
                            <Pen Brush="Silver" Thickness="2"/>
                        </GeometryDrawing.Pen>
                        <GeometryDrawing.Geometry>
                            <RectangleGeometry Rect="9,9,1,1" RadiusX="0" RadiusY="0"/>
                        </GeometryDrawing.Geometry>
                    </GeometryDrawing>
                </DrawingGroup>
            </DrawingBrush.Drawing>
        </DrawingBrush>
        <Style x:Key="DottedStyle" TargetType="tb:DottedCanvas">
            <Setter Property="Background" Value="{StaticResource DottedBrush}"/>
            <Style.Triggers>
                <Trigger Property="DottedEnabled" Value="False">
                    <Setter Property="Background" Value="White"/>
                </Trigger>
            </Style.Triggers>
        </Style>
        <RoutedUICommand x:Key="DeleteCmd" Text="Delete elements"/>
    </UserControl.Resources>
    <UserControl.CommandBindings>
        <CommandBinding Command="Undo" CanExecute="Undo_CanExecute" Executed="Undo_Executed"/>
        <CommandBinding Command="Copy" Executed="CopyCmd_Executed" CanExecute="CopyCmd_CanExecute"/>
        <CommandBinding Command="Paste" CanExecute="Paste_CanExecute" Executed="Paste_Executed"/>
        <CommandBinding Command="Redo" CanExecute="Redo_CanExecute" Executed="Redo_Executed"/>
        <CommandBinding Command="SelectAll" Executed="SelectAll_Executed"/>
        <CommandBinding Command="{StaticResource DeleteCmd}" CanExecute="DeleteCmd_CanExecute" Executed="DeleteCmd_Executed"/>
    </UserControl.CommandBindings>
    <UserControl.InputBindings>
        <KeyBinding Gesture="CTRL+Z" Command="Undo"/>
        <KeyBinding Gesture="CTRL+Y" Command="Redo"/>
        <KeyBinding Gesture="CTRL+A" Command="SelectAll"/>
        <KeyBinding Gesture="CTRL+C" Command="Copy"/>
        <KeyBinding Gesture="CTRL+V" Command="Paste"/>
        <KeyBinding Gesture="CTRL+Ins" Command="Copy"/>
        <KeyBinding Gesture="SHIFT+Ins" Command="Paste"/>
        <KeyBinding Gesture="Del" Command="{StaticResource DeleteCmd}"/>
    </UserControl.InputBindings>
    <tb:DottedCanvas 
        x:Name="TreeCanvas" 
        Style="{StaticResource DottedStyle}"
        AllowDrop="True"
        Focusable="True"
        Drop="TreeCanvas_Drop"
        DragOver="TreeCanvas_DragOver"
        MouseLeftButtonDown="TreeCanvas_MouseLeftButtonDown"
        MouseLeftButtonUp="TreeCanvas_MouseLeftButtonUp"
        MouseRightButtonDown="TreeCanvas_MouseRightButtonDown"
        MouseRightButtonUp="TreeCanvas_MouseRightButtonUp"
        MouseMove="TreeCanvas_MouseMove"
        HorizontalAlignment="Stretch">
    </tb:DottedCanvas>
</UserControl>
